<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>登录</title>
		<link href="css/login.css" rel="stylesheet">
	</head>
	<body>
		<div id="loginDiv">
		    <form action="login.let" method="post" id="form">
		        <h1 id="loginMsg">LOGIN IN</h1>
		        <p>Username:<input id="username" required name="adminName" type="text"></p>
		
		        <p>Password:<input id="password" required name="adminPassword" type="password"></p>
		
		        <div id="subDiv">
		            <input type="submit" class="button" value="login up" id="login">
		            <input type="reset" class="button" value="reset">&nbsp;&nbsp;&nbsp;
		            <a href="register.jsp">没有账号？点击注册</a>
		        </div>
		    </form>
		</div>



		<script>
			let form = document.forms[0];
			console.debug(form);
			form.onsubmit = function(even){
				even.stopPropagation();//阻止事件冒泡
				even.preventDefault();
				fetch("login.let",{
					method:"POST",
					body:new URLSearchParams(new FormData(form)),
					headers:{'Content-Type':'application/x-www-form-urlencoded'},
					credentials:'include'
				}).then(r=>r.json()).then((data)=>{
					if(data.ok){
						window.location = "./admin/index.html";
					}else{
						alert(data.message);
					}
				})
			}
		</script>
	</body>
</html>
